package com.myidis.servlet;

import com.myidis.entity.AnalysisIndex;
import com.myidis.entity.AnalysisIndexBySubject;
import com.myidis.entity.AnalysisTheme;
import com.myidis.mapper.CIDIIndexManagementMapper;
import com.myidis.mapper.QuotaMapper;
import com.myidis.mapper.SubjectAnalyticMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class CIDIIndexManagementServlet {
    @Autowired
    private CIDIIndexManagementMapper CIDIIndexManagementMapper;
    @Autowired
    private SubjectAnalyticMapper subjectAnalyticMapper;
    @Autowired
    private QuotaMapper quotaMapper;

    public ArrayList<AnalysisIndexBySubject> bySubjectList(){
        ArrayList<AnalysisIndexBySubject> a = CIDIIndexManagementMapper.bySubjectList();
        for (AnalysisIndexBySubject e : a){
            System.out.println(e.getQuota());
            e.setQuota(quotaMapper.getOne(Integer.parseInt(e.getQuota())).getChineseName());
        }
        return a;
    }

    public int addToSubject(AnalysisIndexBySubject add){
        return CIDIIndexManagementMapper.insertToSubject(add);
    }

    public int deleteInSubject(int del){
        return CIDIIndexManagementMapper.deleteInSubject(del);
    }

    public ArrayList<AnalysisIndex> byCombinationtList(){
        return CIDIIndexManagementMapper.byCombinationList();
    }
    public ArrayList<AnalysisTheme> list() {
        return subjectAnalyticMapper.allName();
    }

    public int addToCombination(AnalysisIndex add){
        return CIDIIndexManagementMapper.insertToCombination(add);
    }

    public int update(AnalysisIndexBySubject upd){
        return CIDIIndexManagementMapper.update(upd);
    }

    public int deleteInCombination(int del){
        return CIDIIndexManagementMapper.deleteInCombination(del);
    }
}
